﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
        <div class="btn-group">
            <a id="NF-edit" class="btn btn-primary dropdown-text" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
        </div>
        <div class="btn-group">
            <a id="NF-delete" class="btn btn-primary dropdown-text" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入病历号" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

<script>
    $(function () {
        gridList();
    })

    //回车
    $('#txt_keyword').keydownEnterEvent(function () {
        $("#btn_search").trigger('click');
    })

    //明细
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            treeGridModel: "adjacency",
            url: "/KnowledgeBaseManage/MedicalInsurance/SelectMedicalInsuranceFilingList",
            postData: getSearchPostData(),
            height: $(window).height() - 130,
            colModel: [
            { label: "ybbabId", name: "ybbabId", width: 120, align: "left", hidden: true },
            { label: "病历号", name: "blh", width: 120, align: "left" },
            { label: "姓名", name: "xm", width: 120, align: "left" },
            {
                label: "年龄", name: "nlshow", width: 120, align: "left", formatter: function (cellvalue, a, b) {
                    return getAgeFromBirthTime({ begin: b.csny }).text;
                }
            },
            { label: "证件号", name: "zjh", width: 140, align: "left" },
            { label: "病人内码", name: "patId", width: 120, align: "left", hidden: true },
            {
                label: "开始日期", name: "ksrq", width: 120, align: "left",
                formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            },
            {
                label: "结束日期", name: "jsrq", width: 120, align: "left",
                formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            },
            { label: "总次数", name: "zcs", width: 110, align: "left" },
            { label: "剩余次数", name: "sycs", width: 110, align: "left" }
            ],
            pager: "#gridPager",
            sortname: 'CreateTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    page: 1,
                }).trigger('reloadGrid');
        });
    }
    //查询条件
    function getSearchPostData() {
        var keyword = $("#txt_keyword").val();
        return { keyword: keyword};
    };

    //新建
    function btn_add(){
        $.modalOpen({
            id: "PatSerarchView",
            title: "新增医保备案",
            url: "/KnowledgeBaseManage/MedicalInsurance/Form",
            width: "550px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    //修改
    function btn_edit() {
        var seleRowid = jQuery("#gridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var ybbabId = $("#gridList").jqGridRowValue().ybbabId;
        $.modalOpen({
            id: "PatSerarchView",
            title: "修改信息",
            url: "/KnowledgeBaseManage/MedicalInsurance/Form?ybbabId=" + ybbabId,
            width: "550px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    //删除
    function btn_delete() {
        var seleRowid = jQuery("#gridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var ybbabId = $("#gridList").jqGridRowValue().ybbabId;
        $.deleteForm({
            url: "/KnowledgeBaseManage/MedicalInsurance/DeleteForm",
            param: { ybbabId: ybbabId },
            success: function () {
                $("#gridList").trigger("reloadGrid");
            }
        })
    }

</script>

